<template>
  <div class="project-info">
    <el-form :model="projectInfo" label-width="150px">
      <el-row>
        <el-col
          :span="24"
          style="
            display: flex;
            align-items: center;
            justify-content: space-between;
          "
        >
          <h3>项目信息</h3>
          <el-button type="primary" @click="getInfo(true)">刷新</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="项目编号：">
            {{ projectInfo.oaCode }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目状态：">
            {{ projectInfo.status }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目名称：">
            {{ projectInfo.name }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="项目公示：">
            {{ projectInfo.projectNotice }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="发布日期：">
            {{ projectInfo.publishTime }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="征集截止日期：">
            {{ projectInfo.applyEndTime }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="征集起始日期：">
            {{ projectInfo.applyStartTime }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="评审日期：">
            {{ projectInfo.auditTime }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-form :model="form" label-width="220px">
      <h3>项目评审</h3>
      <el-form-item label="项目评审开始时间：">
        <el-input
          v-model="projectInfo.AuditTime"
          placeholder="请输入项目评审开始时间"
          disabled
          style="width: 500px"
        ></el-input>
      </el-form-item>
      <el-form-item label="监督人获得评审授权时间：">
        <el-input
          v-model="projectInfo.supervisorAuthorizationTime"
          placeholder="请输入监督人获得评审授权时间"
          disabled
          style="width: 500px"
        ></el-input>
      </el-form-item>
      <el-form-item label="监督人评审签到时间：">
        <el-input
          v-model="form.startCheckTime"
          placeholder="请先签名"
          disabled
          style="width: 500px"
        ></el-input>
        <span class="link" @click="StartSingin('sign_start')"
          >监督评审签到签名</span
        >
      </el-form-item>
      <el-form-item label="监督人评审签到签名：">
        <div class="tablet">
          <el-image v-if="form.startCheck" :src="baseURL + form.startCheck">
            <template #error>
              <div class="image-slot"></div>
            </template>
          </el-image>
        </div>
      </el-form-item>
      <el-form-item label="监督人评审结果确认签名时间：">
        <el-input
          v-model="form.endCheckTime"
          placeholder="请输入监督人评审结果确认签名时间"
          disabled
          style="width: 500px"
        ></el-input>
        <span class="link" @click="StartSingin('sign_end')"
          >监督评审结果确认签名</span
        >
      </el-form-item>
      <el-form-item label="监督人评审结果确认签名：">
        <div class="tablet">
          <el-image v-if="form.endCheck" :src="baseURL + form.endCheck">
            <template #error>
              <div class="image-slot"></div>
            </template>
          </el-image>
        </div>
      </el-form-item>
    </el-form>
    <sxb ref="Tablet" @Return="Return" style="display: none" />
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRoute } from "vue-router";

import { judgeProjectInfo } from "@/api/project.js";
import { getDictList, getDict, nowTime } from "@/utils/common.js";
import { startJudgeSign, selectMyApply, auditsign } from "@/api/examine.js";
import { ElMessage } from "element-plus";
const route = useRoute();
const id = computed(() => route.query.id);
const baseURL = import.meta.env.VITE_APP_BASE_API;
const Tablet = ref(null);
const userInfo = computed(() => JSON.parse(localStorage.getItem("judgeInfo")));
const projectInfo = ref({
  oaCode: "项目编号",
  name: "项目名称",
  noticeUrl: "项目公示",
  status: "征集中",
  publishTime: "2024-11-01",
  applyStartTime: "2024-11-10",
  applyEndTime: "2024-11-10",
  auditTime: "2024-11-11",
  AuditTime: "123",
});
const form = ref({
  AuditTime: "",
  supervisorAuthorizationTime: "",
  startCheckTime: "",
  startCheck: "",
  supervisorSignature: "",
  restartCheck: "",
  restartCheckTime: "",
});

function submitForm() {
  console.log("Form submitted:", form.value);
  // Add your submission logic here
}
const judgeId = ref("");
const getInfo = (boolean) => {
  judgeProjectInfo({ id: id.value }).then((res) => {
    if (res.code == "200") {
      for (let i = 0; i < res.data.judgeList.length; i++) {
        if (res.data.judgeList[i].userId == userInfo.value.id) {
          judgeId.value = res.data.judgeList[i].id;
          form.value.startCheckTime = res.data.judgeList[i].startCheckTime;
          form.value.startCheck = res.data.judgeList[i].startCheck;
          form.value.restartCheck = res.data.judgeList[i].restartCheck;
          form.value.restartCheckTime = res.data.judgeList[i].restartCheckTime;
          form.value.endCheck = res.data.judgeList[i].endCheck;
          form.value.endCheckTime = res.data.judgeList[i].endCheckTime;
        }
      }
      projectInfo.value = res.data;
      projectInfo.value.supervisorAuthorizationTime = res.data.auditTime;
      projectInfo.value.publishTime = res.data.publishTime
        ? res.data.publishTime.split(" ")[0]
        : "";
      projectInfo.value.applyEndTime = res.data.applyEndTime
        ? res.data.applyEndTime.split(" ")[0]
        : "";
      projectInfo.value.applyStartTime = res.data.applyStartTime
        ? res.data.applyStartTime.split(" ")[0]
        : "";
      projectInfo.value.AuditTime = res.data.auditTime
        ? res.data.auditTime.split(" ")[1]
        : "";
      projectInfo.value.auditTime = res.data.auditTime
        ? res.data.auditTime.split(" ")[0]
        : "";
      projectInfo.value.status = getDict(
        "project_status",
        projectInfo.value.status
      );
      if (boolean) {
        ElMessage({
          message: "刷新成功",
          type: "success",
        });
      }
    }
  });
  getJudge();
};
const getJudge = () => {
  selectMyApply({ projectId: id.value, userId: userInfo.value.id }).then(
    (res) => {
      if (res.code == "200") {
      }
    }
  );
};
const Return = (item) => {
  const params = {
    projectId: id.value,
    projectCode: projectInfo.value.oaCode,
    projectJudgeId: judgeId.value,
    signStr: item,
    type: Sign.value,
  };
  auditsign(params).then((res) => {
    if (res.code == "200") {
      form.value.startCheck = res.data;
      getInfo(true);
    }
  });
};
const Sign = ref("");
const StartSingin = (type) => {
  Sign.value = type;
  Tablet.value.beginSign();
};
onMounted(() => {
  getInfo();
});
</script>

<style scoped>
.project-info {
  padding: 30px;
  border: 1px solid #ddd;
}

h3 {
  margin-top: 20px;
}
:deep(.el-form:last-child > div:last-child > div) {
  margin: 0px !important;
  display: flex;
  justify-content: center;
}
</style>

<style scoped lang="scss">
@use "./judge";
</style>
